

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加修改</title>
    {include file="include/top"}
    <style>
        .layui-form-item .layui-input-inline{width: 80%;}
        #LAY_layedit_2{background: #fff;}
        .layui-input-inline input{border: 0;margin-right: 20px;text-indent: 10px;}
    </style>
</head>
<body>

<div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-app-form-tags" style="padding: 20px 0 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">执行方式</label>
        <div class="layui-input-inline">
            <input type="radio" lay-filter="ctype" name="ctype" value="1" title="统一比例设置" {if !isset($data.ctype)}checked{/if} {if isset($data.ctype) && $data.ctype==1}checked{/if}>
            <input type="radio" lay-filter="ctype" name="ctype" value="2" title="按让利金额" {if isset($data.ctype) && $data.ctype==2}checked{/if}>
            <input type="radio" lay-filter="ctype" name="ctype" value="3" title="选择油号" {if isset($data.ctype) && $data.ctype==3}checked{/if}>
        </div>
    </div>
    {include file="include/input" class2='layui-form-item' type='text' title="备注" name='content' value='<?php echo isset($data["content"])?$data["content"]:"";?>'}
    <div style="max-width: 500px;">
        {include file="include/input" class2='layui-form-item' type='datetime-local' title="执行时间" name='taskTime' value='<?php echo isset($data["taskTime"])?$data["taskTime"]:"";?>'}
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-inline">
            <select name="status" lay-search="" lay-filter="status" lay-search>
                <option value="0" <?php if(isset($data['status']) && $data['status']==0){ echo 'selected';}?>>待执行</option>
                <option value="1" <?php if(isset($data['status']) && $data['status']==1){ echo 'selected';}?>>已执行</option>
                <option value="-1" <?php if(isset($data['status']) && $data['status']==-1){ echo 'selected';}?>>停用</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">执行标签</label>
        <div class="layui-input-inline">
            <div class="layui-btn-container">
                <button type="button" class="layui-btn" lay-demotransferactive="reload">重置</button>
            </div>

            <div id="selectTips" class="demo-transfer"></div>
        </div>
    </div>
    <span id="percentSet" {if isset($data.ctype) && $data.ctype!=1} style="display: none;" {/if}>
    <div class="layui-form-item">
        <label class="layui-form-label">指定油站</label>
        <div class="layui-input-inline selectOil">
            <input type="checkbox" lay-filter="setGasTips" name="setGasTips" value="setGasTips" title="选择标签" <?php echo (isset($data['tipsGasIDS']) && strlen($data['tipsGasIDS'])>0)?'checked':'';?>>
            该模式下若让利为0，表示删除指定
        </div>
    </div>
    <div class="layui-form-item selectGasTips"  <?php echo (isset($data['tipsGasIDS']) && strlen($data['tipsGasIDS'])>0)?'':'style="display: none;"';?>>
        <label class="layui-form-label">指定油站</label>
        <div class="layui-input-inline">
            <div class="layui-btn-container">
                <button type="button" class="layui-btn" lay-demotransferactive="reload2">重置</button>
            </div>

            <div id="selectGasTips" class="demo-transfer"></div>
        </div>
    </div>
        {include file="include/input" class2='layui-form-item' type='text' title="让利%" name='percent' value='<?php echo isset($data["percent"])?$data["percent"]:"";?>'}
    </span>
    <span id="weekPriceSet" {if !isset($data.ctype)} style="display: none;" {/if} {if isset($data.ctype) && $data.ctype!=2} style="display: none;" {/if}>
        {include file="include/input" class2='layui-form-item' type='text' title="让利金额" name='rule' value='<?php echo isset($data["rule"])?$data["rule"]:"";?>'}
    </span>
    <span id="selectOil" {if !isset($data.ctype)} style="display: none;" {/if} {if isset($data.ctype) && $data.ctype!=3} style="display: none;" {/if}>
    <div class="layui-form-item">
        <label class="layui-form-label">油号</label>
        <div class="layui-input-inline selectOil">
            <input type="checkbox" lay-filter="oil_no" name="oil_no" value="92#" title="92#" <?php echo isset($data['inOilArr']) && in_array("92#",$data['inOilArr'])?'checked':'';?>>
            <input type="checkbox" lay-filter="oil_no" name="oil_no" value="95#" title="95#" <?php echo isset($data['inOilArr']) &&  in_array("95#",$data['inOilArr'])?'checked':'';?>>
            <input type="checkbox" lay-filter="oil_no" name="oil_no" value="98#" title="98#" <?php echo isset($data['inOilArr']) &&  in_array("98#",$data['inOilArr'])?'checked':'';?>>
            <input type="checkbox" lay-filter="oil_no" name="oil_no" value="0#" title="0#" <?php echo isset($data['inOilArr']) &&  in_array("0#",$data['inOilArr'])?'checked':'';?>>
        </div>
    </div>
    </span>
    <input name="tipsIDS" type="hidden" value="{$data.tipsIDS?json_encode($data.tipsIDS):''}">
    <input name="tipsGasIDS" type="hidden" value="{$data.tipsGasIDS?json_encode($data.tipsGasIDS):''}">
    <input name="inOil" type="hidden" value="{$data.inOil?$data.inOil:''}">

</div>

{include file="include/js"}
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form','layedit','upload','transfer'],function () {
        var $=layui.$;
        var form=layui.form;
        var upload = layui.upload
        var layedit = layui.layedit;
        var transfer = layui.transfer,util = layui.util;
        function getTipsIDS(){
            var getData = transfer.getData('key123'); //获取右侧数据
            $("input[name='tipsIDS']").val(JSON.stringify(getData))
        }
        function getGasTipsIDS(){
            var getData = transfer.getData('gasSelect'); //获取右侧数据
            $("input[name='tipsGasIDS']").val(JSON.stringify(getData))
        }
        $(function (){
            setSelect()
            setGasSelect()
            getTipsIDS()
            getGasTipsIDS()
        })
        // 图片接口放到建立编辑器前面，否则无效
        layedit.set({
            uploadImage: {
                url: '/users/uploadimg', //接口url
                type: 'post' //默认post
            }
        });
        form.on("checkbox(setGasTips)",function (re){
           var $check = re.elem.checked
            if($check){
                $(".selectGasTips").show(200)
            }else{
                $(".selectGasTips").hide(200)
            }
        })
        function selectOil(){
            var temArr="";
            $("input[name='oil_no']:checked").each(function (){
                var obj = $(this)
                temArr += obj.val()+","
            })
            $("input[name='inOil']").val(temArr.replace(/^\,+|\,+$/g, ''))
        }
        form.on("checkbox(oil_no)",function (){
            selectOil()

        })
        // 设置编辑器
        layedit.build('content', {
            height: 500 //设置编辑器高度
            ,background:"#ffffff"
        });
        form.on("radio(ctype)",function (){
            var value = $(this).val()
            $("#weekPriceSet").hide()
            $("#selectOil").hide()
            $("#percentSet").hide()
            if(value==1){
                $("#percentSet").show()
            }else if(value==3){
                $("#selectOil").show()
            }else{
                $("#weekPriceSet").show()
            }
        })
        var index = layedit.build('content'); //建立编辑器
        form.verify({ // 这里就是把富文本数据同步到<textarea>中
            content: function (value) {
                return layedit.sync(index);
            }
        });
        function setGasSelect(){
            //实例调用
            transfer.render({
                    elem: '#selectGasTips'
                    ,data: {$tipsAllGasIDS | raw}
                ,id: 'gasSelect' //定义唯一索引
                ,showSearch: true
                ,title: ['可选油站标签', '已选油站标签']
                ,width:"40%"
                ,onchange:function (){
                getGasTipsIDS()
                },
            })
            {if strlen($data.tipsIDS)>2}
            transfer.reload('gasSelect', {
                value: {$data.tipsGasIDS | raw}
            })
            {/if}
                //批量办法定事件
                util.event('lay-demoTransferActive', {
                    getData: function(othis){
                        var getData = transfer.getData('selectGasTips'); //获取右侧数据
                        layer.alert(JSON.stringify(getData));
                    }
                    ,reload2:function(){
                        //实例重载
                        transfer.reload('gasSelect', {
                            value: []
                        })
                        getGasTipsIDS()
                    }
                });}
        function setSelect(){
            //实例调用
            transfer.render({
                elem: '#selectTips'
                ,data: {$tipsAllIDS | raw}
                ,id: 'key123' //定义唯一索引
                ,showSearch: true
                ,title: ['可选标签', '已选标签']
                ,width:"40%"
                ,onchange:function (){
                    getTipsIDS()
                },
            })
            {if strlen($data.tipsIDS)>2}
            transfer.reload('key123', {
                value: {$data.tipsIDS | raw}
            })
            {/if}
            //批量办法定事件
            util.event('lay-demoTransferActive', {
                getData: function(othis){
                    var getData = transfer.getData('key123'); //获取右侧数据
                    layer.alert(JSON.stringify(getData));
                }
                ,reload:function(){
                    //实例重载
                    transfer.reload('key123', {
                        value: []
                    })
                    getTipsIDS()
                }
            });}
    });
</script>
</body>
</html>